/*
	PlAr is Platform Arena: a 2D multiplayer shooting game
	Copyright (c) 2010, Antonio Ragagnin <spocchio@gmail.com>
    All rights reserved.

    This file is licensed under the New BSD License.
 */

package res.players;

import java.util.ArrayList;
import java.util.HashMap;

import org.jbox2d.common.Vec2;

import plar.core.Action;
import plar.core.Common;

import plar.core.KeyFlag;
import plar.core.Sprite;
import plar.core.ElementPlayer;
import plar.core.ActionTimer;
import plar.core.SpriteSet;

public class Queen extends ElementPlayer {
    public class SpriteManager extends Action {
        int firing = 0;

        int index = 0;
        int maxFiring = 50;
        HashMap<String, SpriteSet> spriteSet;

        public SpriteManager() {
            spriteSet = new HashMap<String, SpriteSet>();
            spriteSet.put("move_right", new SpriteSet());
            spriteSet.put("move_left", new SpriteSet());
            spriteSet.put("jump_right", new SpriteSet());
            spriteSet.put("jump_left", new SpriteSet());
            spriteSet.put("stop_right", new SpriteSet());
            spriteSet.put("stop_left", new SpriteSet());
            spriteSet.put("fire_left", new SpriteSet());
            spriteSet.put("fire_right", new SpriteSet());
            spriteSet.put("pogo", new SpriteSet());
            spriteSet.put("jumpfire_left", new SpriteSet());
            spriteSet.put("jumpfire_right", new SpriteSet());
            spriteSet.put("down_left", new SpriteSet());
            spriteSet.put("down_right", new SpriteSet());
            String p = "res/players/qeen/";
            spriteSet.get("pogo").add(new Sprite(p + "queenp.png", 0.1f));
            spriteSet.get("stop_right").add(new Sprite(p + "queensr.png", 0.1f));
            spriteSet.get("stop_left").add(new Sprite(p + "queensl.png", 0.1f));
            spriteSet.get("move_right").add(new Sprite(p + "queenrr0.png", 0.1f));
            spriteSet.get("move_right").add(new Sprite(p + "queenrr1.png", 0.1f));
            spriteSet.get("move_right").add(new Sprite(p + "queenrr2.png", 0.1f));
            spriteSet.get("move_right").add(new Sprite(p + "queenrr3.png", 0.1f));
            spriteSet.get("move_left").add(new Sprite(p + "queenrl0.png", 0.1f));
            spriteSet.get("move_left").add(new Sprite(p + "queenrl1.png", 0.1f));
            spriteSet.get("move_left").add(new Sprite(p + "queenrl2.png", 0.1f));
            spriteSet.get("move_left").add(new Sprite(p + "queenrl3.png", 0.1f));
            spriteSet.get("jump_left").add(new Sprite(p + "queenjl0.png", 0.1f));
            spriteSet.get("jump_right").add(new Sprite(p + "queenjr0.png", 0.1f));
            spriteSet.get("fire_left").add(
                new Sprite(p + "queenfl.png", new Vec2(0.5f, 0.7f), 0.1f));
            spriteSet.get("fire_right").add(
                new Sprite(p + "queenfr.png", new Vec2(0.5f, 0.7f), 0.1f));
            spriteSet.get("jumpfire_left").add(
                new Sprite(p + "queenjfl0.png", 0.1f));
            spriteSet.get("jumpfire_right").add(
                new Sprite(p + "queenjfr0.png", 0.1f));
            spriteSet.get("down_right").add(new Sprite(p + "queendr.png", 0.1f));
            spriteSet.get("down_left").add(new Sprite(p + "queendl.png", 0.1f));

        }

        public void run() {

            boolean isRunning = (getSpeed().x != 0);

            if (firing > maxFiring)
                firing = 0;
            String spriteSuffix;
            if (directionX < 0)
                spriteSuffix = "_left";
            else
                spriteSuffix = "_right";
            String spriteName = new String();

            if (firing > 0 || isFiring) {
                if (isJumping)
                    spriteName = "jumpfire";
                else
                    spriteName = "fire";
                firing++;
            } else if (isJumping && hasPogo)
            {   spriteName = "pogo";
                spriteSuffix="";
            } else if (isJumping)

                spriteName = "jump";
            else if (isBending)
                spriteName = "down";
            else if (isRunning && !isJumping)
                spriteName = "move";
            else if (!isRunning && !isJumping)
                spriteName = "stop";





            if (spriteName.equals(""))
                Common.info(1, "no sprite selected!");
            //else

            spriteName += spriteSuffix;
            //	Common.info(1, "spriteName="+spriteName);
            currentSpriteSet = spriteSet.get(spriteName);

        }
    }

    public boolean hasPogo;

    public Queen() {
        super();
        actions.addAction("actionManager", new SpriteManager());
        name = "Commander Queen";
        description = "use the SPECIAL key to jump with your POGO";
        presentation = "res/players/qeen/queenl.png";

    }

    public void specialMove(KeyFlag k) {
        if (!isJumping) {
            //Common.info(1,"POGO!");
            setSpeed(new Vec2(0, -jumpSpeed*2));
            ((ActionTimer)actions.getAction("jumptime")).active=true;
            hasPogo = true;
        }

    }

    public void allKeysReleased() {
        if (!isJumping)
            hasPogo = false;

    }

}
